package com.hxci.web.bean;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class WhitelistUrl {
    private static final String FILE_PATH = "C:\\wpdcd\\code\\bookmanager\\src\\main\\webapp\\WEB-INF\\db.url";

    public static List<String> readWhitelist() {
        List<String> whitelist = new ArrayList<>();
        // 使用BufferedReader和FileReader从文件中读取内容
        try (BufferedReader reader = new BufferedReader(new FileReader(FILE_PATH))) {
            String line;
            while ((line = reader.readLine()) != null) {
                whitelist.add(line); // 将每一行内容添加到白名单列表中
            }
            System.out.println("白名单已从 " + FILE_PATH + " 读取");
        } catch (IOException e) {
            System.err.println("读取白名单时发生错误: " + e.getMessage());
        }
        return whitelist;
    }

    public static void saveWhitelist(List<String> whitelist) {
        // 使用BufferedWriter和FileWriter将内容写入文件
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(FILE_PATH))) {
            for (String item : whitelist) {
                writer.write(item);
                writer.newLine(); // 每个条目占一行
            }
            System.out.println("白名单已保存到 " + FILE_PATH);
        } catch (IOException e) {
            System.err.println("保存白名单时发生错误: " + e.getMessage());
        }
    }
    public static List<String> whitelist(){
        List<String> publicUrls = Arrays.asList("/login.jsp", "/loginAdmin.jsp", "/register.jsp", "/index.jsp","/images","/book1.jsp","/styles.css","/about.jsp","/images/2.jpg",
                "/userxx.jsp","/profile.jsp","/css/styles1.css","/css/styles.css","/user.jsp","/book.jsp","/main.jsp","/right.jsp","/left.jsp","/top.jsp");
        return publicUrls;
    }
}
